﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using DistanceLearning.Models;

namespace DistanceLearning
{
    public static class ConnectionHelper
    {
        public static string GetSchoolConnection(int schoolId)
        {
            var schoolConnectionName = string.Format("SchoolConnection{0}", schoolId);
            var schoolConnectionSettings = ConfigurationManager.ConnectionStrings[schoolConnectionName];
            var schoolConnectionString = schoolConnectionSettings != null
                                             ? schoolConnectionSettings.ConnectionString
                                             : string.Empty;
            return schoolConnectionString;
        }
    }

    public static class DateHelper
    {
        //public static string[] DaysOfWeek = new[] {"Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота", "Воскресенье"};
        public static DayOfWeek[] DaysOfWeek = new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday };

        public static IEnumerable<KeyValuePair<int,DayOfWeek>> GetDaysOfWeek()
        {
            int i = 0;
            return DaysOfWeek.Select(day => new KeyValuePair<int, DayOfWeek>(i++, day));
        }

        public static string GetRussianValue(DayOfWeek dayOfWeek)
        {
            switch (dayOfWeek)
            {
                case DayOfWeek.Monday: return "Понедельник";
                case DayOfWeek.Tuesday: return "Вторник";
                case DayOfWeek.Wednesday: return "Среда";
                case DayOfWeek.Thursday: return "Четверг";
                case DayOfWeek.Friday: return "Пятница";
                case DayOfWeek.Saturday: return "Суббота";
                case DayOfWeek.Sunday: return "Воскресенье";
                default: return "";
            }
        }

        public static DayOfWeek GetDayOfWeek(int day)
        {
            if (day > 6 || day < 0)
                throw new Exception("Неверное значение дня недели");
            return DaysOfWeek[day];
        }

        public static TimeSpan BeginLesson(int lessonOrder)
        {
            int hours = 0, minutes = 0;
            switch (lessonOrder)
            {
                case 0: hours = 8; minutes = 0; break;
                case 1: hours = 9; minutes = 0; break;
                case 2: hours = 10; minutes = 0; break;
                case 3: hours = 11; minutes = 0; break;
                case 4: hours = 12; minutes = 0; break;
                case 5: hours = 13; minutes = 0; break;
                case 6: hours = 14; minutes = 0; break;
                case 7: hours = 15; minutes = 0; break;
                default: throw new Exception("Превышено количество уроков. Максималоное количество - 8");
            }
            return new TimeSpan(0, hours, minutes);
        }
    }

    public static class JournalStatic
    {
        public const string AdminRole = "Admin";
        public const string SchoolAdminRole = "SchoolAdmin";
        public const string Parent = "Parent";
        public const string Pupil = "Pupil";
        public const string Teacher = "Teacher";
        public const string CompositeRole = "Admin,Teacher,SchoolAdmin";
    }

    public static class ConfigurationTableHelper
    {
        public const string Timetable = "Timetable"; // if set then timetable exists
    }
}